<?php
require_once('../../../../conf/config.php.inc');
require_once(SYBMAS_LIB_PATH.'/liblogin.php.inc');
require_once(SYBMAS_LAYOUT_PATH.'/layout.php.inc');
require_once(SYBMAS_LIB_PATH.'/libsybmas.php.inc');
require_once(SYBMAS_LAYOUT_PATH.'/menu.php.inc');
require_once('../../lib/libtablas.php.inc');
verificar_inicio_sesion();	

if(array_key_exists('function',$_GET)){
		$parameters=$_GET;
	}else if (array_key_exists('function',$_POST)){
		$parameters=$_POST;
	}else{
		die('Se requiere especificar el nombre de la funcion a invocar');
	}
	$function=trim($parameters['function']);

	switch ($function){
		case 'getColumnsByTable':
			$id=$parameters['id'];
			$data=getColumnsByTable($id);
			break;
		default:
			die("Funcion desconocida: $function ".$_SERVER['QUERY_STRING']);	
	}
	
	echo $data;	


function getColumnsByTable($id){
	$html="";
	if (empty($id)) {
		$html ="<option></option>\n";
	} else {		
		$sybuser_connection=start_default_sybuser_connection();
		$query="SELECT c.colid,c.name,t.name AS type,c.length,c.prec,c.scale ".		
		"FROM syscolumns c, systypes t ".
		"WHERE c.id=$id ".
		"AND c.usertype*=t.usertype";
		$result=@sybase_query($query,$sybuser_connection);
		$firstLoop=true;
		while($data=sybase_fetch_array($result)){
			$name=$data['name'];
			$type=$data['type'];
			$length=$data['length'];
			$prec=$data['prec'];
			$scale=$data['scale'];
			
			if(isset($prec) && isset($scale)){
				$type.="($prec,$scale)";				
			}else if(isset($length)){
				$type.="($length)";
			}
			if(!$firstLoop){
				$html.="|";
			}
			$html.="$name=$name($type)";
			$firstLoop=false;
		}		
		sybase_close($sybuser_connection);		
	}
	return $html;
}

?>

